package kit.edu.lego.gruppe3.levels.fallingBridge;

import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSolver;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import kit.edu.lego.gruppe3.levels.bridge.BridgeSolver;
import kit.edu.lego.gruppe3.levels.door.DoorSolver;
import kit.edu.lego.gruppe3.levels.labyrinth.LabyrinthSolver;
import kit.edu.lego.gruppe3.levels.rollbridge.RollBridgeSolver;
import kit.edu.lego.gruppe3.levels.sumpf.SumpfSolver;
import kit.edu.lego.gruppe3.levels.treeArea.TreeAreaSolver;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;

public class FallingBridgeSolver implements LevelSolver
{

	@Override
	public void start()
	{
		finishPreviousLevels();
		LevelSelector.getInstance().setCurrentLevel(Level.fallingBridge);
		System.out.println("Falling bridge level");
		Behavior moveOnRight = new MoveOnRightSide();
		Behavior moveFromEdge = new FallingBridgeEdgeEvader();
		Behavior fallingBridgeEnd = new FallingBridgeEnd();
		Behavior fallingBridgeWallEvader = new RightWallEvader();
		
		Behavior[] bridgeBehaviors = {moveOnRight, moveFromEdge, fallingBridgeWallEvader, fallingBridgeEnd};
		
		Arbitrator arby = new Arbitrator(bridgeBehaviors, true);
	
		arby.start();
	}
	
	private void finishPreviousLevels()
	{
		LabyrinthSolver.setLevelCleared(true);
		SumpfSolver.setLevelCleared(true);
		RollBridgeSolver.setLevelCleared(true);
		DoorSolver.setLevelCleared(true);
		TreeAreaSolver.setLevelCleared(true);
		BridgeSolver.setLevelCleared(true);
	}

	private static boolean levelCleared = false;
	
	public static boolean isLevelCleared()
	{
		return levelCleared;
	}
	
	public static void setLevelCleared(boolean cleared)
	{
		levelCleared = cleared;
	}

}
